<template>
    <div>
      <ul>
        <li v-for="(item,index) in activeData" :key="index">
          <img :src="item.avatar" alt="">
          <div class="act2-right">
            <p>{{item.user_login}}</p>
            <p>{{item.content}}</p>
            <p>
              <span>{{item.create_time | simplyToRelativeTime}}</span>
              <img @click="like3(item)" :src="item.status==1?'./static/lyl/like.png':'./static/lyl/like2.png'" alt="">
            </p>
          </div>
        </li>
      </ul>
    </div>
</template>

<script>
  import * as list from "../../../api/list.js";
    export default {
      name: "Dynamic",
      data(){
        return {
          activeData:[]
        }
      },
      methods:{
        like3(itl){
          if (itl.status==1){
            itl.status=0;
            let parms = {
              id:itl.id,
              user_id:this.$store.state.user_id,
              status:itl.status
            };
            list.activeDynamicLike(parms).then(res=>{
              console.log(res);
            })
          } else{
            itl.status=1;
            let parms = {
              id:itl.id,
              user_id:this.$store.state.user_id,
              status:itl.status
            };
            list.activeDynamicLike(parms).then(res=>{
              console.log(res);
            })
          }
        }
      },
      beforeMount(){
        let parmes3 = {
          id:this.$route.params.id2,
          type:2,
          user_id:this.$store.state.user_id,
        };
        list.activeDynamic(parmes3).then(res=>{
          console.log(res);
          this.activeData = res.data;
        })
      },
      mounted(){
        mui.back = function() {
          window.history.go(-1);
        }
      },
      filters:{
        simplyToRelativeTime(timestamp) {
          let currentUnixTime = Math.round((new Date()).getTime() / 1000);       // 当前时间的秒数
          let deltaSecond = currentUnixTime - parseInt(timestamp, 10);            // 当前时间与要转换的时间差（ s ）
          let result;

          if (deltaSecond < 60) {
            result = deltaSecond + '秒前';
          } else if (deltaSecond < 3600) {
            result = Math.floor(deltaSecond / 60) + '分钟前';
          } else if (deltaSecond < 86400) {
            result = Math.floor(deltaSecond / 3600) + '小时前';
          } else {
            result = Math.floor(deltaSecond / 86400) + '天前';
          }
          return result;
        }
      }
    }
</script>

<style scoped>
  ul{
    padding: 20px 40px;
  }
  ul li{
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #dcdcdc;
    margin-bottom: 20px;
  }
  ul li:last-child{
    border-bottom: none;
  }
  ul li>img{
    width: 90px;
    height: 90px;
    border-radius: 100%;
    background: #bfbfbf;
  }
  ul li .act2-right{
    width: 550px;
    margin-left: 20px;
  }
  ul li .act2-right p:nth-child(1){
    font-size: 32px;
    margin-bottom: 10px;
  }
  ul li .act2-right p:nth-child(2){
    font-size: 24px;
    line-height: 36px;
  }
  ul li .act2-right p:nth-child(3){
    display: flex;
    justify-content: space-between;
    padding: 40px 0;
  }
  ul li .act2-right p:nth-child(3) span{
    font-size: 24px;
    line-height: 36px;
    color: #8c8c8c;
  }
  ul li .act2-right p:nth-child(3) img{
    width: 26px;
    height: 30px;
  }
</style>
